const {ControlResponseCodeSuccess} = require("./ControlResponse");
const {createRegisterPrefixCommand} = require("./FibCommands");
const {ControlParameters} = require("../component/ControlParameters");
const {createMIRController} = require("./MIRController");

class RegisterPrefixHelper {
    registerPrefix(identifier, face, keychain){
        let controller = createMIRController(function () {
            return face
        }, false, keychain)

        let parameters = new ControlParameters()
        parameters.setPrefix(identifier)
        let commandExecutor = controller.prepareCommandExecutor(createRegisterPrefixCommand("/min-mir/mgmt/localhost", parameters))
        let response = commandExecutor.start()

        if (response.code !== ControlResponseCodeSuccess)
            throw new Error(response.msg)
    }
}

module.exports = {
    RegisterPrefixHelper: RegisterPrefixHelper
}